package com.avic.rong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.bean.HomeBean;
import com.avic.rong.listener.CriterionItemOnClickListener;
import com.example.minato.minastore.utils.AppUtils;
import com.example.minato.minastore.utils.GlideApp;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Creater: Created by wangyz on 2017/1/10.
 * Email: 936804097@qq.com
 */

public class LibraryAdapter extends RecyclerView.Adapter<LibraryAdapter.RecommandViewHolder> {


    private Context mContext;
    private List<HomeBean.CriterionBean> data = new ArrayList<>();

    public LibraryAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<HomeBean.CriterionBean> list){
        this.data = list;
        notifyDataSetChanged();
    }

    @Override
    public LibraryAdapter.RecommandViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.view_library, parent, false);
        RecommandViewHolder holder = new RecommandViewHolder(view, viewType);

        return holder;
    }

    @Override
    public void onBindViewHolder(LibraryAdapter.RecommandViewHolder holder, final int position) {

        GlideApp.with(mContext).load(AppUtils.IMG2_URL + data.get(position).getTargetImg())
                .placeholder(R.mipmap.empty)
                .into(holder.img_category);
        holder.tv_category_name.setText(data.get(position).getTargetName());
        holder.tv_category_price.setText("¥" + data.get(position).getPrice());
        holder.itemView.setOnClickListener(new CriterionItemOnClickListener(mContext, AppUtils.BASE_URL + "app/good/info/" + data.get(position).getSkuId() + ".html"));

    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    class RecommandViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_category_name)
        TextView tv_category_name;
        @BindView(R.id.img_category)
        ImageView img_category;
        @BindView(R.id.tv_category_price)
        TextView tv_category_price;

        public RecommandViewHolder(View itemView, int type) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
